package com.ophiux.cs.infrastructure.repositories.appraise;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.ophiux.cs.domain.appraise.model.entity.CsUserAppraises;
import com.ophiux.cs.domain.appraise.model.valueobj.DoctorAppraiseDetailObj;
import com.ophiux.cs.domain.appraise.model.valueobj.DoctorAppraiseQueryObj;
import com.ophiux.cs.domain.appraise.model.valueobj.DoctorAppraiseValueObj;
import com.ophiux.cs.domain.appraise.repositories.IAppraiseRepository;
import com.ophiux.cs.infrastructure.mapper.appraise.AppraiseMapper;
import com.ophiux.utils.exception.OphiuxDaoException;
import com.ophiux.utils.exception.OphiuxRepositoryException;

import lombok.extern.slf4j.Slf4j;

@Repository
@Slf4j
public class AppraiseRepository implements IAppraiseRepository {
	@Autowired
	AppraiseMapper appraiseMapper;

	@Override
	public void save(CsUserAppraises obj) throws OphiuxRepositoryException {
		try {
			CsUserAppraises newObj = appraiseMapper.getAppraiseByAppraiseId(obj.getAPPRAISE_ID());
			if(newObj==null) {
				appraiseMapper.insert(obj);
			}else {
				appraiseMapper.update(obj);
			}
		} catch (Exception e) {
			e.printStackTrace();
			log.info("数据库执行异常,异常信息",e);
			throw new OphiuxRepositoryException(e);
		}
	}
	
	@Override
	public List<DoctorAppraiseValueObj> getCSDoctorAppraiseMaster(DoctorAppraiseQueryObj dar) throws OphiuxRepositoryException {
		List<DoctorAppraiseValueObj> darList=null;
		try {
			darList=appraiseMapper.getCSDoctorAppraiseMaster(dar);
		} catch (OphiuxDaoException e) {
			e.printStackTrace();
			throw new OphiuxRepositoryException("查询医生评价汇总异常", e);
		}
		return darList;
	}

	@Override
	public List<DoctorAppraiseDetailObj> getCSDoctorAppraiseDetails(DoctorAppraiseQueryObj dar) throws OphiuxRepositoryException {
		List<DoctorAppraiseDetailObj> darList=null;
		try {
			darList=appraiseMapper.getCSDoctorAppraiseDetails(dar);
		} catch (OphiuxDaoException e) {
			e.printStackTrace();
			throw new OphiuxRepositoryException("查询医生评价详情异常", e);
		}
		return darList;
	}

}
